package com.kyh.util.sys;

import java.util.List;
import java.util.Map;

import com.alibaba.fastjson.JSON;
import com.kyh.enume.sys.ColEnum;
import com.kyh.mapper.CommonMapper;
import com.kyh.sys.entity.Col;
import com.kyh.sys.entity.Menu;
import com.kyh.sys.mapper.SysCommonMapper;
import com.kyh.util.IDUtils;
import com.kyh.util.MethodUtil;
import com.kyh.util.StringBoUtil;
import com.kyh.util.StringUtils;

public class ColUtil {
	
	
	public static String getCheckbox() {
		
//		return "{checkbox: true,align: 'center',valign: 'middle'}";
		return "{checkbox: true}";
	}
	
	
	public static String getIndexno() {
		
		return "{field: 'SerialNumber',title: '序号',sortable: true,align: 'center',width: 40,formatter: function (value, row, index) {return index + 1;}}";
	}
	
	/*
	 * 获取bootstrap table的columns
	 */
	public static String getColumns(List<Col> listCol, Menu menu, SysCommonMapper sysCommonMapper, CommonMapper commonMapper) {
		StringBuffer sb = new StringBuffer("[" + getCheckbox());
		if (menu.getMenuIsShowNo() == ColEnum.StatusIsShowNo.YES.value) {
			sb.append("," + getIndexno());
		}
		for (Col col : listCol) {
			Integer colType = col.getColType();
			if (col.getColStatusShow() == ColEnum.StatusShow.YES.value) {
				if (colType == ColEnum.ColType.TEXT.value) {
					sb.append(getColumnText(col));
				} else if (colType == ColEnum.ColType.SELECTOR.value) {
					List<Map<String, Object>> listOption;
					if (col.getColSelectors().contains("from sys_")) {
						listOption = sysCommonMapper.list(col.getColSelectors());
					} else {
						listOption = commonMapper.list(col.getColSelectors());
					}
					sb.append(getColumnSelector(col, listOption));
				} else if (colType == ColEnum.ColType.SELECTOR_MODAL.value) {
					List<Map<String, Object>> listOption;
					if (col.getColSelectors().contains("from sys_")) {
						listOption = sysCommonMapper.list(col.getColSelectors());
					} else {
						listOption = commonMapper.list(col.getColSelectors());
					}
					sb.append(getColumnSelector(col, listOption));
				} else if (colType == ColEnum.ColType.IMG.value) {
					sb.append(getColumnImg(col));
				} else if (colType == ColEnum.ColType.DATE_YYMMDD_HH_mm_ss.value) {
					sb.append(getColumnDate(col));
				} else if (colType == ColEnum.ColType.TEXTAREA.value) {
					sb.append(getColumnTextarea(col));
				} else if (colType == ColEnum.ColType.FILE.value) {
					sb.append(getColumnFile(col));
				}
			}
		}
		return sb.toString() + "]";
	}
	
	/*
	 * 获取新增页面的输入框
	 */
	public static String getInputsAdd(List<Col> listCol, SysCommonMapper sysCommonMapper, CommonMapper commonMapper, Map<String, Object> entity) {
		StringBuffer sb = new StringBuffer("");
		for (Col col : listCol) {
			String colCode = col.getColCode();
			Integer colType = col.getColType();
			String colName = col.getColName();
			String colSelectors = col.getColSelectors();
			Object value = getValue(entity, colCode);
			
			String colValueOnload = col.getColValueOnload();
			if (colValueOnload != null && colValueOnload.length() > 0) {
				sb.append(getInputHidden(colCode, colValueOnload));
			}

			if (col.getColStatusAdd() == 1) {
				if (colType == ColEnum.ColType.TEXT.value) {
					sb.append(getInputText(colCode, col.getColName(), col.getColStatusValidate(), value.toString()));
//					sb.append(getInputText(col, value.toString()));
				} else if (colType == ColEnum.ColType.SELECTOR.value) {
					List<Map<String, Object>> listOption;
					if (colSelectors.contains("from sys_")) {
						listOption = sysCommonMapper.list(colSelectors);
					} else {
						listOption = commonMapper.list(colSelectors);
					}
					sb.append(getInputSelect(colCode, col.getColName(), listOption, value));
//					sb.append(getInputSelect(col, "add", listOption, value));
				} else if (colType == ColEnum.ColType.HYPE_TEXT.value) {
					sb.append(getInputHypeText(colCode, colName, value));
				} else if (colType == ColEnum.ColType.IMG.value) {
					sb.append(getInputImg(colCode, colName, value));
				} else if (colType == ColEnum.ColType.DATE_YYMMDD_HH_mm_ss.value || colType == ColEnum.ColType.DATE_YYMMDD_00_00_00.value || colType == ColEnum.ColType.DATE_YYMMDD_23_59_59.value) {
					sb.append(getInputDate(colCode, colName, colType, value));
				} else if (colType == ColEnum.ColType.TEXTAREA.value) {
					sb.append(getInputTextarea(colCode, colName, value));
				} else if (colType == ColEnum.ColType.SELECTOR_MODAL.value) {
					sb.append(getInputSelectorModal(col, "add", value, sysCommonMapper, commonMapper));
				} else if (colType == ColEnum.ColType.FILE.value) {
					sb.append(getInputFile(colCode, colName, value));
				}
			}
		}
		return sb.toString();
	}
	
	/**
	 * @param pk_name 格式：如：merchant_id
	 * 获取编辑页面的输入框
	 */
	public static String getInputsEdit(List<Col> listCol, String pk_name, SysCommonMapper sysCommonMapper, CommonMapper commonMapper, Map<String, Object> entity) {

		StringBuffer sb = new StringBuffer("");
		for (Col col : listCol) {
			String colCode = col.getColCode();
			Integer colType = col.getColType();
			String colName = col.getColName();
			String colSelectors = col.getColSelectors();
			Object value = getValue(entity, colCode);
			
			// 主键ID
			if (colCode.equals(StringBoUtil.lowerFirst(StringUtils.replaceUnderlineAndfirstToUpper(pk_name)))) {
				sb.append("<input type='hidden' class='form-control bo-input-" + colType + "' name='" + colCode + "' value='" + entity.get(colCode) + "'>");
				continue;
			}
			
			//  默认加载值
			String colValueOnload = col.getColValueOnload();
			if (colValueOnload != null && colValueOnload.length() > 0) {
				sb.append("<input type='hidden' class='form-control' name='" + colCode + "' value='" + colValueOnload + "'>");
				continue;
			}
			
			if (col.getColStatusEdit() == ColEnum.StatusEdit.YES.value) {
				if (colType == ColEnum.ColType.TEXT.value) {
					sb.append(getInputText(colCode, col.getColName(), col.getColStatusValidate(), value.toString()));
//					sb.append(getInputText(col, value.toString()));
				} else if (colType == ColEnum.ColType.SELECTOR.value) {
					List<Map<String, Object>> listOption;
					if (colSelectors.contains("from sys_")) {
						listOption = sysCommonMapper.list(colSelectors);
					} else {
						listOption = commonMapper.list(colSelectors);
					}
					sb.append(getInputSelect(colCode, col.getColName(), listOption, value));
				} else if (colType == ColEnum.ColType.HYPE_TEXT.value) {
					sb.append(getInputHypeText(colCode, colName, value));
				} else if (colType == ColEnum.ColType.IMG.value) {
					sb.append(getInputImg(colCode, colName, value));
				} else if (colType == ColEnum.ColType.DATE_YYMMDD_HH_mm_ss.value || colType == ColEnum.ColType.DATE_YYMMDD_00_00_00.value || colType == ColEnum.ColType.DATE_YYMMDD_23_59_59.value) {
					sb.append(getInputDate(colCode, colName, colType, value));
				} else if (colType == ColEnum.ColType.TEXTAREA.value) {
					sb.append(getInputTextarea(colCode, colName, value));
				} else if (colType == ColEnum.ColType.SELECTOR_MODAL.value) {
					sb.append(getInputSelectorModal(col, "edit", value, sysCommonMapper, commonMapper));
				} else if (colType == ColEnum.ColType.FILE.value) {
					sb.append(getInputFile(colCode, colName, value));
				}
			}
		}
		return sb.toString();
	}
	
	/*
	 * 获取搜索的输入框
	 */
	public static String getInputsSearch(List<Col> listCol, SysCommonMapper sysCommonMapper, CommonMapper commonMapper) {
		StringBuffer sb = new StringBuffer("");
		for (Col col : listCol) {
			String colName = col.getColName();
			String colCode = col.getColCode();
			Integer colType = col.getColType();
			String colSelectors = col.getColSelectors();
			if (col.getColStatusSearch() == 1) {
				if (colType == ColEnum.ColType.TEXT.value) {
					sb.append("<div class='form-group'><input type='text' class='form-control' placeholder='" + colName + "' name='" + colCode + "'></div>");
				} else if (colType == ColEnum.ColType.SELECTOR.value) {
					sb.append("<div class='form-group'><select class='form-control' name='" + colCode + "'>");
					
					sb.append("<option value=''>请选择" + colName + "</option>");
					List<Map<String, Object>> listOption;
					if (colSelectors.contains("from sys_")) {
						listOption = sysCommonMapper.list(colSelectors);
					} else {
						listOption = commonMapper.list(colSelectors);
					}
					// 拼接选项
					for (Map<String, Object> option : listOption) {
						sb.append("<option value='" + option.get("optionValue") + "'>" + option.get("optionName") + "</option>");
					}
					sb.append("</select></div>");
				} else if (colType == ColEnum.ColType.DATE_YYMMDD_HH_mm_ss.value
						|| colType == ColEnum.ColType.DATE_YYMMDD_00_00_00.value
						|| colType == ColEnum.ColType.DATE_YYMMDD_23_59_59.value) {
					
					int minView = 2; // 0代表最小选择到时分秒，2代表最小选择到日期
					
					String idDiv = "id_div_search_" + col.getColId();
					String formatString = "yyyy-mm-dd ";
					if (colType == ColEnum.ColType.DATE_YYMMDD_HH_mm_ss.value) {
						formatString += "hh:ii:ss";
						minView = 0;
					} else if (colType == ColEnum.ColType.DATE_YYMMDD_00_00_00.value) {
						formatString += "00:00:00";
					} else if (colType == ColEnum.ColType.DATE_YYMMDD_23_59_59.value) {
						formatString += "23:59:59";
					}

					sb
					.append("<div class='input-group date' id='" + idDiv + "'>")
					.append("<input class='form-control bo-input-" + colType + "' placeholder='请选择" + colName + "' name='" + colCode + "' type='text' readonly value=''>")
					.append("<span class='input-group-addon'><span class='glyphicon glyphicon-remove'></span></span>")
					.append("<span class='input-group-addon'><span class='glyphicon glyphicon-calendar'></span></span>")
					.append("</div>");;
					
					sb.append("<script>")
						.append("$(function () {")
							.append("$('#" + idDiv + "').datetimepicker({")
								.append("language:  'zh-CN',")
								.append("format: '" + formatString + "',")
								.append("weekStart: 1,")
								.append("todayBtn:  1,")
								.append("autoclose: 1,")
								.append("todayHighlight: 1,")
								.append("startView: 2,")
								.append("minView: " + minView + ",")
								.append("forceParse: 0,")
								.append("clearBtn: true")
							.append("});")
						.append("});")
					.append("</script>");
					
				} else if (colType == ColEnum.ColType.BOOLEAN.value) {
					sb
					.append("<div class='input-group date bo-div-" + colType + "'>")
					.append("<input class='form-control' placeholder='请选择" + colName + "' name='" + colCode + "' type='text' readonly>")
					.append("<span class='input-group-addon'><span class='glyphicon glyphicon-remove'></span></span>")
					.append("<span class='input-group-addon'><span class='glyphicon glyphicon-calendar'></span></span>")
					.append("</div>");
					sb.append("<div class='form-group'><label control-label'>" + colName + "：</label><input data-on-text='是' data-off-text='否' data-size='small' data-on-color='success' type='checkbox' name='" + colCode + "' unchecked></div>");
				} else if (colType == ColEnum.ColType.SELECTOR_MODAL.value) {
					String objId = "search_" + col.getColId();
					sb.append("<div class='form-group'><input type='hidden' name='" + colCode + "' id='" + objId + "'>");
					sb.append("<input readonly class='form-control' placeholder='请选择" + colName + "' onclick='showPageUrl(\"selector?objId=" + objId + "&colId=" + col.getColId() + "\")' />");
					sb.append("<button type='button' class='btn btn-warning btn-sm' onclick='clearSelectorModal(\"" + objId + "\", \"请选择" + colName + "\")'><i class='fa fa-eraser' aria-hidden='true'> 清空</i></button>");
					sb.append("</div>");
				}
			}
		}
		
		return sb.toString();
	}
	
	/**
	 * @param pkName 格式：withdraw_id
	 * 获取列表初始化的param
	 */
	public static String getJsParamsInit(Menu menu, String pkName, List<Col> listCol) {
		StringBuffer sb = new StringBuffer("");
		
		for (Col col : listCol) {

			String colValueOnload = col.getColValueOnload();
			if (colValueOnload != null && colValueOnload.length() > 0) {
				sb.append(col.getColCode() + ": '" + col.getColValueOnload() + "',");
			}
		}
		
		String menuorderby = menu.getMenuOrderBy();
		String menusorttype = menu.getMenuSortType();
		if (menuorderby == null || menuorderby.length() == 0) {
			if (pkName.length() > 0) {
				sb.append("orderby : '" + pkName + "',");
				sb.append("sorttype : '" + menusorttype + "'");
			}
		} else {
			sb.append("orderby : '" + menuorderby + "',");
			sb.append("sorttype : '" + menusorttype + "'");
		}
		return sb.toString();
	}
	
	public static String getInputText(String colCode, String colName, Integer colStatusValidate, String value) {

		StringBuffer sb = new StringBuffer("");
		sb.append("<div class='form-group col-md-6'><label class='col-sm-3 control-label'>" + colName + "</label><div class='col-md-9'>");
		if (colStatusValidate == ColEnum.StatusValidate.YES.value) {
			sb.append("<input type='text' class='form-control' name='" + colCode + "' data-bv-notempty data-bv-notempty-message='" + colName + "不能为空' placeholder='请输入" + colName + "' value='" + value + "'>");
		} else {
			sb.append("<input type='text' class='form-control' name='" + colCode + "' placeholder='请输入" + colName + "' value='" + value + "'>");
		}
		sb.append("</div></div>");
		return sb.toString();
	}
	
	public static String getInputSelect(String colCode, String colName, List<Map<String, Object>> listOption, Object value) {
		
		String idSelect = "id_" + MethodUtil.createUniqueRandom();

		StringBuffer sb = new StringBuffer("");
		sb.append("<div class='form-group col-md-6'><label class='col-sm-3 control-label'>" + colName + "</label><div class='col-md-9'>");
		sb.append("<select class='form-control' name='" + colCode + "' id='" + idSelect + "'>");
		sb.append("<option value=''>请选择" + colName + "</option>");

		// 拼接选项
		for (Map<String, Object> option : listOption) {
			sb.append("<option value='" + option.get("optionValue") + "'>" + option.get("optionName") + "</option>");
		}
		
		sb.append("</select>");
		sb.append("</div></div>");
		
		if (value != null) {
		sb.append("<script>")
			.append("$(function () {")
				.append("$('#" + idSelect + "').val('" + value + "');")
			.append("});")
		.append("</script>");
		}
		return sb.toString();
	}
	
	private static String getInputSelectorModal(Col col, String addOrEdit, Object value, SysCommonMapper sysCommonMapper, CommonMapper commonMapper) {
		String colSelectores = col.getColSelectors();
		String valueText = "";
		if ("edit".equals(addOrEdit) && value != null && !"".equals(value)) {
			String sql = "select AA.optionName from (" + colSelectores + ") AA where AA.optionValue = '" + value + "'";
			if (colSelectores.contains("from sys_")) {
				valueText = sysCommonMapper.getString(sql);
			} else {
				valueText = commonMapper.getString(sql);
			}
		}
		
		String colName = col.getColName();
		String colCode = col.getColCode();
		
		String objId = addOrEdit + "_" + col.getColId();

		StringBuffer sb = new StringBuffer("");
		sb.append("<div class='input-group col-md-6'><label class='col-sm-3 control-label'>" + colName + "</label><div class='col-md-9'>");
		sb.append("<input name='" + colCode + "' type='hidden' id='" + objId + "' value='" + value + "'/>");
		sb.append("<input readonly class='form-control' placeholder='请选择" + colName + "' onclick='showPageUrl(\"selector?objId=" + objId + "&colId=" + col.getColId() + "\")' value='" + valueText + "' />");
		sb.append("<button type='button' class='input-group-addon btn btn-warning btn-sm' onclick='clearSelectorModal(\"" + objId + "\", \"请选择" + colName + "\")'><i class='fa fa-eraser' aria-hidden='true'> 清空</i></button>");
		sb.append("</div></div>");
		return sb.toString();
	}
	
	public static String getInputHypeText(String colCode, String colName, Object value) {

		StringBuffer sb = new StringBuffer("");
		String idHiddenHtml = "id_hidden_html_" + MethodUtil.createUniqueRandom();
		String idHiddenInput = "id_hidden_input_" + MethodUtil.createUniqueRandom();
		String idDiv = "id_div_" + MethodUtil.createUniqueRandom();

		sb.append("<div class='form-group col-lg-12'><label class='col-sm-3 control-label'>" + colName + "</label>")
		.append("<div class='col-sm-9'>")
		.append("<div id='" + idHiddenHtml + "' style='display:none;'>" + value + "</div>")
		.append("<input type='hidden' name='" + colCode + "' id='" + idHiddenInput + "' value='' />")
		.append("<div class='web-edit-div'>")
		.append("<div id='" + idDiv + "' class='web-content'></div>")
		.append("</div>")
		.append("</div>");
		sb.append("</div>");
		
		sb.append("<script>")
			.append("$(function () {")
				.append("var datas = $('#" + idHiddenHtml + "').html();")
				.append("$('#" + idHiddenInput + "').val(datas);")
				.append("$BO.initKindEditor('" + idDiv + "', '" + idHiddenInput + "', datas);")
			.append("});")
		.append("</script>");
		
		return sb.toString();
	}
	
	public static String getInputImg(String colCode, String colName, Object value) {
		String idImg = "id_img_" + MethodUtil.createUniqueRandom();
		String idInput = "id_input_" + MethodUtil.createUniqueRandom();

		StringBuffer sb = new StringBuffer("");
		sb
		.append("<div class='form-group col-md-12'>")
		.append("	<label class='col-sm-3 control-label'>" + colName + "</label>")
		.append("	<div class='col-sm-9'>")
		.append("		<div class='file-loading'>")
		.append("			<input class='file' type='file' data-theme='fas' id='" + idImg + "'>")
		.append("		</div>")
		.append("		<input type='hidden' name='" + colCode + "' value='" + value + "' id='" + idInput + "' />")
		.append("	</div>")
		.append("</div>");
		
		sb.append("<script>")
			.append("$(function () {")
			.append("$BO.initFileInput($('#" + idImg + "'), $('#" + idInput + "'), '" + value + "');")
			.append("});")
		.append("</script>");
		
		return sb.toString();
	}
	
	public static String getInputFile(String colCode, String colName, Object value) {
		String idFile = "id_file_" + MethodUtil.createUniqueRandom();
		String idInput = "id_input_" + MethodUtil.createUniqueRandom();

		StringBuffer sb = new StringBuffer("");
		sb
		.append("<div class='form-group col-md-12'>")
		.append("	<label class='col-sm-3 control-label'>" + colName + "</label>")
		.append("	<div class='col-sm-9'>")
		.append("		<div class='file-loading'>")
		.append("			<input class='file' type='file' data-theme='fas' id='" + idFile + "'>")
		.append("		</div>")
		.append("		<input type='hidden' name='" + colCode + "' value='" + value + "' id='" + idInput + "' />")
		.append("	</div>")
		.append("</div>");
		
		sb.append("<script>")
			.append("$(function () {")
			.append("$BO.initOtherFileInput($('#" + idFile + "'), $('#" + idInput + "'), '" + value + "');")
			.append("});")
		.append("</script>");
		
		return sb.toString();
	}
	
	public static String getInputDate(String colCode, String colName, Integer colType, Object value) {
		String idDiv = "id_div_" + MethodUtil.createUniqueRandom();
		String formatString = "yyyy-mm-dd ";
		if (colType == ColEnum.ColType.DATE_YYMMDD_HH_mm_ss.value) {
			formatString += "hh:ii:ss";
		} else if (colType == ColEnum.ColType.DATE_YYMMDD_00_00_00.value) {
			formatString += "00:00:00";
		} else if (colType == ColEnum.ColType.DATE_YYMMDD_23_59_59.value) {
			formatString += "23:59:59";
		}
		
		String valueStr = "";
		if (value != null && value.toString().length() > 0) {
			valueStr = value.toString().substring(0, 19);
		}

		StringBuffer sb = new StringBuffer("");

		sb.append("<div class='form-group col-md-6'><label class='col-sm-3 control-label'>" + colName + "</label><div class='col-sm-9'>")
		.append("<div class='input-group date' id='" + idDiv + "'>")
		.append("<input class='form-control bo-input-" + colType + "' placeholder='请选择" + colName + "' name='" + colCode + "' type='text' readonly value='" + valueStr + "'>")
		.append("<span class='input-group-addon'><span class='glyphicon glyphicon-remove'></span></span>")
		.append("<span class='input-group-addon'><span class='glyphicon glyphicon-calendar'></span></span>")
		.append("</div>");
		sb.append("</div></div>");
		
		sb.append("<script>")
			.append("$(function () {")
				.append("$('#" + idDiv + "').datetimepicker({")
					.append("language:  'zh-CN',")
					.append("format: '" + formatString + "',")
					.append("weekStart: 1,")
					.append("todayBtn:  1,")
					.append("autoclose: 1,")
					.append("todayHighlight: 1,")
					.append("startView: 2,")
					.append("minView: 0,")
					.append("forceParse: 0,")
					.append("clearBtn: true")
				.append("});")
			.append("});")
		.append("</script>");
		return sb.toString();
	}
	
	public static String getInputTextarea(String colCode, String colName, Object value) {
		
		String idDivHidden = "id_div_hidden_" + MethodUtil.createUniqueRandom();
		String idInput = "id_input_" + MethodUtil.createUniqueRandom();

		StringBuffer sb = new StringBuffer("");
		sb.append("<div class='form-group col-md-12'><label class='col-sm-3 control-label'>" + colName + "</label><div class='col-md-9'>");
		sb.append("<div style='display:none;' id='" + idDivHidden + "'>" + value + "</div>");
		sb.append("<textarea class='form-control' name='" + colCode + "' placeholder='请输入" + colName + "' rows='5' id='" + idInput + "' value=''></textarea>");
		sb.append("</div></div>");
		
		sb.append("<script>")
			.append("$(function () {")
			.append("$('#" + idInput + "').val($('#" + idDivHidden + "').html());")
			.append("});")
		.append("</script>");
		return sb.toString();
	}
	
	private static String getColumnText(Col col) {
		String colName = col.getColName();
		String colCode = col.getColCode();
		String colScripts = col.getColScripts();
		int colStatusListEdit = col.getColStatusListEdit();

		StringBuffer sb = new StringBuffer("");

		sb.append(",{title: '" + colName + "',field: '" + colCode + "',align: 'center',valign: 'middle'");
		if (colScripts != null && colScripts.length() > 0) {
			sb.append("," + colScripts);
		} else if (colStatusListEdit == ColEnum.StatusListEdit.YES.value) {
			sb.append(",editable: {type: 'text',title: '" + colName + "',validate: function (v) {if (!v) return '不能为空';}}");
		}
		sb.append("}");
		return sb.toString();
	}
	
	private static String getColumnTextarea(Col col) {
		String colName = col.getColName();
		String colCode = col.getColCode();
		String colScripts = col.getColScripts();

		StringBuffer sb = new StringBuffer("");
		
		sb.append(",{title: '" + colName + "',field: '" + colCode + "',align: 'center',valign: 'middle'");
		if (colScripts != null && colScripts.length() > 0) {
			sb.append("," + colScripts);
		}
		sb.append("}");
		return sb.toString();
	}
	
	private static String getColumnSelector(Col col, List<Map<String, Object>> listOption) {
		String colName = col.getColName();
		String colCode = col.getColCode();
		int colStatusListEdit = col.getColStatusListEdit();

		StringBuffer sb = new StringBuffer("");
		
		sb.append(",{title: '" + colName + "',field: '" + colCode + "',align: 'center',valign: 'middle'");
		if (colStatusListEdit == ColEnum.StatusListEdit.YES.value) {
			sb.append(",editable: {type: 'select',title: '" + colName + "',source:");
			sb.append(OptionUtil.arrSelect(listOption).toJSONString());
			sb.append("}");
		} else {
			sb.append(",formatter: function (value, row, index) {var keyValueMap = " + JSON.toJSONString(OptionUtil.toMap(listOption)) + "; return keyValueMap[value];}");
		}
		sb.append("}");
		return sb.toString();
	}
	
	private static String getColumnImg(Col col) {
		String colName = col.getColName();
		String colCode = col.getColCode();

		StringBuffer sb = new StringBuffer("");
		
		sb.append(",{title: '" + colName + "',field: '" + colCode + "',align: 'center',valign: 'middle'");
		sb.append(",formatter: function (value, row, index) {var returnStr = '';if (value == '' || value === undefined) {returnStr += '无';} else {returnStr += '<a class=\"pictip\" href=\"' + value + '\" target=\"blank\"><img style=\"width: 50px; height:80px;\" src=\"' + value + '\" /></a>';}return returnStr;}");
		sb.append("}");
		return sb.toString();
	}
	
	private static String getColumnFile(Col col) {
		String colName = col.getColName();
		String colCode = col.getColCode();

		StringBuffer sb = new StringBuffer("");
		
		sb.append(",{title: '" + colName + "',field: '" + colCode + "',align: 'center',valign: 'middle'");
		sb.append(",formatter: function (value, row, index) {var returnStr = '';if (value == '' || value === undefined) {returnStr += '无';} else {returnStr += '<a class=\"pictip\" href=\"' + value + '\" target=\"blank\"><img style=\"width: 50px; height:80px;\" src=\"' + value + '\" /></a>';}return returnStr;}");
		sb.append("}");
		return sb.toString();
	}
	
	private static String getColumnDate(Col col) {
		String colName = col.getColName();
		String colCode = col.getColCode();

		StringBuffer sb = new StringBuffer("");
		
		sb.append(",{title: '" + colName + "',field: '" + colCode + "',align: 'center',valign: 'middle'}");
		return sb.toString();
	}
	
	private static Object getValue(Map<String, Object> entity, String colCode) {
		Object value = "";
		if (entity != null && entity.containsKey(colCode)) {
			value = entity.get(colCode);
		}
		return value;
	}
	
	/**
	 * 获取隐藏的输入框
	 * @param colCode
	 * @param value
	 * @return
	 */
	public static String getInputHidden(String colCode, String value) {

		StringBuffer sb = new StringBuffer("");
		sb.append("<input type='hidden' name='" + colCode + "' value='" + value + "'>");
		return sb.toString();
	}
	
	/**
	 * 获取只读的输入框
	 * @param colCode
	 * @param colName
	 * @param value
	 * @return
	 */
	public static String getInputReadOnly(String colCode, String colName, String value) {

		StringBuffer sb = new StringBuffer("");
		sb.append("<div class='form-group col-md-6'><label class='col-sm-3 control-label'>" + colName + "</label><div class='col-md-9'>");
		sb.append("<input type='text' class='form-control' name='" + colCode + "' value='" + value + "' readonly>");
		sb.append("</div></div>");
		return sb.toString();
	}
	
	public static void main(String[] args) {
		System.out.println(IDUtils.commonOrderNo());
	}
}
